
#include "dev_off.h"
#include "../res/img_common.h"
#include "pt_fs.h"
#include "sys_font.h"

static void common_power_on_event_callback(lv_event_t* event)
{
    
}

int ui_dev_off_create(lv_obj_t* parent,ui_dev_off_t* dev_off)
{
    dev_off->bg_img = lv_img_create(parent);
    #if 0
    lv_img_set_src(dev_off->bg_img,pt_fs_get("BG_shutdown.png"));
    #else
    lv_img_set_src(dev_off->bg_img,&BG_shutdown);
    #endif
    lv_obj_set_pos(dev_off->bg_img,0,0);
    //***************************************************************************
    dev_off->btn_img = lv_img_create(parent);
    lv_img_set_src(dev_off->btn_img,pt_fs_get("Power3_Default.png"));
    lv_obj_set_pos(dev_off->btn_img,183,195);
    //*****************************************
    dev_off->title = lv_label_create(parent);
    lv_obj_set_pos(dev_off->title,94,85);
    lv_obj_set_size(dev_off->title,264,70);
    lv_obj_set_style_text_align(dev_off->title,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(dev_off->title,LV_OPA_80,LV_PART_MAIN);
    lv_obj_set_style_text_color(dev_off->title,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_font(dev_off->title, lv_font_get(60), LV_STATE_DEFAULT);
    lv_label_set_text( dev_off->title, "已关机");
    //*****************************************
    dev_off->btn = lv_obj_create(parent);

    lv_obj_set_pos(dev_off->btn,191,195);
    midea_ui_safe_set_size(dev_off->btn,100,100);

	lv_obj_set_style_radius(dev_off->btn, 0, LV_PART_MAIN);
	lv_obj_set_style_border_width(dev_off->btn, 0, LV_PART_MAIN);
	lv_obj_set_style_border_color(dev_off->btn, lv_color_make(0x00, 0x00, 0x00), LV_PART_MAIN);
	lv_obj_set_style_border_opa(dev_off->btn, LV_OPA_0, LV_PART_MAIN);

	lv_obj_set_style_outline_width(dev_off->btn, 0, LV_PART_MAIN);
	lv_obj_set_style_shadow_width(dev_off->btn, 0, LV_PART_MAIN);
	lv_obj_set_scrollbar_mode(dev_off->btn, LV_SCROLLBAR_MODE_OFF);
	lv_obj_set_style_pad_all(dev_off->btn, 0,0);

    #if 1
    lv_obj_set_style_bg_opa(dev_off->btn,LV_OPA_0,0);
    #else
    lv_obj_set_style_bg_opa(dev_off->btn,LV_OPA_100,0);
    lv_obj_set_style_bg_color(dev_off->btn,lv_color_make(0xff,0,0),0);
    #endif

    lv_obj_clear_flag(dev_off->btn,LV_OBJ_FLAG_GESTURE_BUBBLE);
    lv_obj_add_event_cb(dev_off->btn, common_power_on_event_callback, LV_EVENT_ALL,(void*)dev_off);

    return 0;
}

int ui_dev_off_destroy(ui_dev_off_t* dev_off)
{
    if(dev_off->bg_img){
        lv_obj_del(dev_off->bg_img);
        dev_off->bg_img = NULL;
    }
    if(dev_off->btn_img){
        lv_obj_del(dev_off->btn_img);
        dev_off->btn_img = NULL;
    }
    if(dev_off->title){
        lv_obj_del(dev_off->title);
        dev_off->title = NULL;
    }
        if(dev_off->btn){
        midea_ui_safe_del_obj(dev_off->btn);
        dev_off->btn = NULL;
    }

    //*****************************************

    return 0;
}

int ui_dev_off_hide(ui_dev_off_t* dev_off)
{
    if(!dev_off){
        return -1;
    }

    if(dev_off->bg_img){
        lv_obj_add_flag(dev_off->bg_img, LV_OBJ_FLAG_HIDDEN);
    }
    if(dev_off->btn_img){
        lv_obj_add_flag(dev_off->btn_img, LV_OBJ_FLAG_HIDDEN);
    }   
    if(dev_off->title){
        midea_ui_safe_add_flag(dev_off->title, LV_OBJ_FLAG_HIDDEN);
    }
    if(dev_off->btn){
        midea_ui_safe_add_flag(dev_off->btn, LV_OBJ_FLAG_HIDDEN);
    }

    return 0;
}


int ui_dev_off_show(ui_dev_off_t* dev_off)
{
    if(!dev_off){
        return -1;
    }

    if(dev_off->bg_img){
        lv_obj_clear_flag(dev_off->bg_img, LV_OBJ_FLAG_HIDDEN);
    }
    if(dev_off->btn_img){
        lv_obj_clear_flag(dev_off->btn_img, LV_OBJ_FLAG_HIDDEN);
    }   
    if(dev_off->title){
        lv_obj_clear_flag(dev_off->title, LV_OBJ_FLAG_HIDDEN);
    }
    if(dev_off->btn){
        midea_ui_safe_clear_flag(dev_off->btn, LV_OBJ_FLAG_HIDDEN);
    }

    return 0;
}
